import sys

def main(filename: str):
    queues = dict()
    with open(filename) as f:
        for line in f.readlines():
            if line.count(':')<2:
                continue
            time, queuename, data = line.split(":")
            data = data.strip()
            if queuename not in queues.keys():
                queues[queuename] = []
            queues[queuename].append(data)
    w = queues['w']
    r = queues['r']
    for i, data in enumerate(w):
        if data != r[i]:
            print("w{}!=r{}".format(i, i))
        else:
            print("pass w{}:{}".format(i, data))


class Check:
    def __init__(self):
        pass

    def buildQueues(self, filepath: str) -> dict:
        queues = dict()
        with open(filepath) as f:
            for line in f.readlines():
                if line.count(':')<2:
                    continue
                time, queuename, data = line.split(":")
                data = data.strip()
                if queuename not in queues.keys():
                    queues[queuename] = []
                queues[queuename].append((time, data))
        return queues
    def buildCheckPairs(self, filepath:str) -> list:
        pairs=None
        with open(filepath) as f:
            for line in f.readlines():
                if '[' in line:
                    pairs=eval(line)
                    break
        return pairs
    def checkPairs(self, queues: dict, pairs: list):
        for pair in pairs:
            self.checkPair(queues[pair[0]], queues[pair[1]])

    def checkPair(self, l0: list, l1: list):
        try:
            for i, item in enumerate(l0):
                if(item[1] != l1[i][1]):
                    print("time {}: unmatched data {}".format(*item))
                else:
                    print("time {}: matched data {}".format(*item))
        except IndexError as e:
            print(e)
    def runThis(self, filepath:str):
        queues=self.buildQueues(filepath)
        pairs=self.buildCheckPairs(filepath)
        self.checkPairs(queues,pairs)

if __name__ == '__main__':
    Check().runThis(sys.argv[1])
